/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ebasclient.abstracts.guielements;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author Luca
 */
public class MyAbstractTableRenderer<T extends MyAbstractTableModel<E>, E extends JPanel> extends DefaultTableCellRenderer {

    private Color selectedColor;

    public Color getSelectedColor() {
        return selectedColor;
    }

    public void setSelectedColor(Color selectedColor) {
        this.selectedColor = selectedColor;
    }

    public MyAbstractTableRenderer() {
        selectedColor = Color.YELLOW;
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        Object panel = ((T) table.getModel()).getValueAt(row, column);
        E singleVar = (E) ((T) table.getModel()).getValueAt(row, column);

        singleVar.setOpaque(true);
        if (isSelected) {
            singleVar.setBackground(selectedColor);
            return (Component) panel;
        } else {
            singleVar.setOpaque(true);
            singleVar.setBackground(null);
        }
        return (Component) panel;
    }
    
}
